package fiber

import "github.com/gofiber/fiber/v2"

type Result struct {
	Code int       `json:"code"`
	Msg  string    `json:"msg"`
	Data fiber.Map `json:"data"`
}

func NewResult(code int, msg string, data fiber.Map) Result {
	return Result{
		Code: code,
		Msg:  msg,
		Data: data,
	}
}

func Succeed(data fiber.Map) Result {
	return NewResult(0, "success", data)
}

func failed(code int, msg string) Result {
	return NewResult(code, msg, fiber.Map{})
}

func FailedWithErrCode(errCode ErrorCode) Result {
	return failed(errMap[errCode].Code, errMap[errCode].Msg)
}
